import 'package:flutter/material.dart';
import '../home1_3.dart';

class NotificationPage extends StatelessWidget {
  const NotificationPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: const Color(0xFF1DC4A0),
        elevation: 0,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios, color: Colors.white),
          //onPressed: () => Navigator.pop(context),
          onPressed: () {
            Navigator.pushReplacementNamed(context, '/home1_3');
          },
        ),
        title: const Text(
          '提醒',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w600,
          ),
        ),
        actions: [
          IconButton(
            icon:
                Image.asset('assets/icons/settings.png', width: 24, height: 24),
            onPressed: () {},
          ),
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            _buildNotificationCard(
              context,
              '19分钟后请服药',
              '药品1，250 mg - 1片 - 饭前服用',
              'assets/icons/med1.png',
              '今日10:00',
            ),
            const SizedBox(height: 20),
            _buildNotificationCard(
              context,
              '9小时后请服药',
              '药品2，250 mg - 1片 - 饭前服用',
              'assets/icons/med2.png',
              '今日18:29',
            ),
          ],
        ),
      ),
      bottomNavigationBar: Container(
        padding: const EdgeInsets.symmetric(vertical: 12),
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1),
              blurRadius: 10,
              offset: const Offset(0, -2),
            ),
          ],
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            _buildNavItem(
              iconPath: 'assets/icons/home.png',
              selectedIconPath: 'assets/icons/home.png',
              label: '首页',
              isSelected: false,
              onTap: () {
                Navigator.pushReplacementNamed(context, '/home1_3');
              },
            ),
            _buildNavItem(
              iconPath: 'assets/icons/calendar.png',
              selectedIconPath: 'assets/icons/calendar.png',
              label: '服药日程',
              isSelected: false,
              onTap: () => Navigator.pushReplacementNamed(
                  context, '/medication_schedule'),
            ),
            _buildNavItem(
              iconPath: 'assets/icons/notification.png',
              selectedIconPath: 'assets/icons/notification.png',
              label: '消息',
              isSelected: true,
              onTap: () {},
            ),
            _buildNavItem(
              iconPath: 'assets/icons/profile.png',
              selectedIconPath: 'assets/icons/profile.png',
              label: '我的',
              isSelected: false,
              onTap: () {
                Navigator.pushReplacementNamed(context, '/profile');
              },
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildNavItem({
    required String iconPath,
    required String selectedIconPath,
    required String label,
    required bool isSelected,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Stack(
            alignment: Alignment.bottomCenter,
            children: [
              // 图标
              Image.asset(
                iconPath,
                width: 24,
                height: 24,
                color: isSelected ? const Color(0xFF1DC4A0) : Colors.grey,
              ),
              // 选中指示器
              if (isSelected)
                Positioned(
                  bottom: -8,
                  child: Image.asset(
                    'assets/icons/chosen.png',
                    width: 16,
                    height: 3,
                  ),
                ),
            ],
          ),
          const SizedBox(height: 8),
          Text(
            label,
            style: TextStyle(
              color: isSelected ? const Color(0xFF1DC4A0) : Colors.grey,
              fontSize: 12,
              fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildNotificationCard(BuildContext context, String title,
      String subtitle, String iconPath, String time) {
    return Card(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12),
      ),
      elevation: 2,
      child: ListTile(
        leading: Image.asset(iconPath, width: 40, height: 40),
        title: Text(
          title,
          style: const TextStyle(
            fontSize: 16,
            fontWeight: FontWeight.w600,
          ),
        ),
        subtitle: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(subtitle),
            const SizedBox(height: 5),
            Text(
              time,
              style: const TextStyle(
                fontSize: 12,
                color: Colors.grey,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
